﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OTS.Model;
using OTS.BLL;

public partial class gallery_grid : System.Web.UI.Page
{
    ProductBLL productBLL = new ProductBLL();
    ProductTypeBLL proTypeBLL = new ProductTypeBLL();
    Brand brand = new Brand();
    product_type proType = new product_type();
    BrandBLL brandBLL = new BrandBLL();
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dataTable = new DataTable();
        if (!IsPostBack)
        {
            if (Request.QueryString["typeID"] != null || Request.QueryString["name"] != null || Request.QueryString["price1"] != null || Request.QueryString["price2"] != null)
            {
                MyDs();
                ViewState["pagen"] = 0; //当前第pagen+1页
            }
            else
            {
                MyDs();
                //Response.Redirect("Index.aspx");
            }

            dataTable = proTypeBLL.GetAllType();
            this.rpType.DataSource = dataTable;
            this.rpType.DataBind();

            dataTable = brandBLL.GetAllBrand();
            this.rpBrand.DataSource = dataTable;
            this.rpBrand.DataBind();

            BindMaterial();
            BindMat();
            BindExpirySeason();
        }
    }

    /// <summary>
    /// 绑定面料
    /// </summary>
    private void BindMaterial()
    {
        string MaterialFile = Server.MapPath("XML/Material.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(MaterialFile);
        DataTable dt = ds.Tables[0];
        this.rpMaterial.DataSource = dt;
        this.rpMaterial.DataBind();
    }

    private void BindMat()
    {
        string MatFile = Server.MapPath("XML/Mat.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(MatFile);
        DataTable dt = ds.Tables[0];
        this.rpMat.DataSource = dt;
        this.rpMat.DataBind();
    }

    /// <summary>
    /// 绑定季节
    /// </summary>
    private void BindExpirySeason()
    {
        string ExpirySeason = Server.MapPath("XML/ExpirySeason.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(ExpirySeason);
        DataTable dt = ds.Tables[0];
        this.rpExpirySeason.DataSource = dt;
        this.rpExpirySeason.DataBind();
    }

    private void MyDs()
    {
        string sqlText = "";
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string typeID = Request.QueryString["typeID"];
        string brandID = Request.QueryString["brandID"];
        string expirySeason = Request.QueryString["expirySeason"];
        string name = Request.QueryString["name"];
        string price1 = Request.QueryString["price1"];
        string price2 = Request.QueryString["price2"];

        if (typeID != null && brandID==null)
        {
            dt = productBLL.GetTypeByProduct("where product.typeId=" + typeID);
            dTable = productBLL.GetTotal("where typeId=" + typeID);
            this.panelType.Visible = false;

            proType = proTypeBLL.GetModel(Int32.Parse(typeID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (typeID!=null && brandID != null)
        {
            sqlText = "where product.typeId=" + typeID + " and product.brandID=" + brandID;
            dt = productBLL.GetTypeByProduct(sqlText);
            dTable = productBLL.GetTotal(sqlText);
            this.panelType.Visible = false;
            this.panelBrand.Visible = false;

            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Int32.Parse(typeID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID!=null && expirySeason!="")
        {
            sqlText = "where product.brandID=" + brandID + " and product.expirySeason=" + expirySeason;
            dt = productBLL.GetTypeByProduct(sqlText);
            dTable = productBLL.GetTotal(sqlText);
            this.panelBrand.Visible = false;
            this.panelExpirySeason.Visible = false;
        }
        else
        {
            dt = productBLL.GetAllProduct();
            dTable = productBLL.GetTotal();

            //this.lblSitemaps.Visible = false;
            //this.Label1.CssClass = "divDisplayN";
        }

        if (name != null || price1 != null || price2 != null)     //首页模糊查询及分页
        {
            string strWhere = " where ";
            string strDesc = " order by wholeSalePrice desc";
            string strAsc = " order by wholeSalePrice asc";

            if (name != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "title like'%" + name + "%'");
                dTable = productBLL.GetTotal(strWhere + "title like'%" + name + "%'");
            }
            else if (price1 != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "wholeSalePrice between " + price1 + " and (select MAX(wholeSalePrice) from product)" + strAsc);
                dTable = productBLL.GetTotal(strWhere + "wholeSalePrice between " + price1 + " and (select MAX(wholeSalePrice) from product)");
            }
            else if (price2 != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "wholeSalePrice between " + price2 + " and (select MIN(wholeSalePrice) from product)" + strDesc);
                dTable = productBLL.GetTotal(strWhere + "wholeSalePrice between " + price2 + " and (select MIN(wholeSalePrice) from product)");
            }
            else if (name != null && price1 != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price1 + " and (select MAX(wholeSalePrice) from product)" + strAsc);
                dTable = productBLL.GetTotal(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price1 + " and (select MAX(wholeSalePrice) from product)");
            }
            else if (name != null && price2 != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price2 + " and (select MIN(wholeSalePrice) from product)" + strDesc);
                dTable = productBLL.GetTotal(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price2 + " and (select MIN(wholeSalePrice) from product)");
            }
            else if (name != null && price1 != null && price2 != null)
            {
                dt = productBLL.GetAllProduct(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price1 + " and " + price2 + strAsc);
                dTable = productBLL.GetTotal(strWhere + "title like'%" + name + "%' and " + "wholeSalePrice between " + price1 + " and " + price2);
            }
            else
            {
                dt = productBLL.GetAllProduct();
                dTable = productBLL.GetTotal();
            }
        }
        
        proPage(dt, dTable);
    }

    private void proPage(DataTable dt, DataTable dTable)
    {
        //截取数据库取出的图片信息
        //创建表
        DataSet ds = new DataSet("typeBypro");   //创建一个名为ShowPic的DataSet
        DataTable table = new DataTable("typeBypro");    //创建名为ShowPic的DataTable
        table.Columns.Add(new DataColumn("tb_id", typeof(int)));
        table.Columns.Add(new DataColumn("tb_proNO", typeof(string)));
        table.Columns.Add(new DataColumn("tb_wholeSalePrice", typeof(float)));
        table.Columns.Add(new DataColumn("tb_retailPrice", typeof(float)));
        table.Columns.Add(new DataColumn("tb_zhekou", typeof(string)));
        table.Columns.Add(new DataColumn("tb_showpic", typeof(string)));
        table.Columns.Add(new DataColumn("tb_expirySeason", typeof(string)));
        table.Columns.Add(new DataColumn("tb_title", typeof(string)));

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = table.NewRow();
            dr["tb_id"] = dt.Rows[i]["proID"];
            dr["tb_proNO"] = dt.Rows[i]["proNO"].ToString();
            dr["tb_wholeSalePrice"] = dt.Rows[i]["wholeSalePrice"].ToString();

            //计算折扣
            if (Convert.ToInt32(dt.Rows[i]["retailPrice"].ToString()) == 0 || Convert.ToInt32(dt.Rows[i]["retailPrice"].ToString()) == Convert.ToInt32(dt.Rows[i]["wholeSalePrice"].ToString()))
            {
                dr["tb_retailPrice"] = dt.Rows[i]["wholeSalePrice"].ToString();
                dr["tb_zhekou"] = "0";
            }
            else
            {
                double discount = (Convert.ToInt32(dt.Rows[i]["retailPrice"].ToString()) / Convert.ToInt32(dt.Rows[i]["wholeSalePrice"].ToString())) * 10;
                dr["tb_zhekou"] = discount.ToString();
            }
            if (dt.Rows[i]["basicInformation_pic"].ToString()=="")
            {
                dr["tb_showpic"] = "img/yes_picture.gif";
            }
            else
            {
                dr["tb_showpic"] = dt.Rows[i]["bigImg_pic"].ToString();
            }
            dr["tb_expirySeason"] = dt.Rows[i]["expirySeason"].ToString();
            dr["tb_title"] = dt.Rows[i]["title"].ToString();
            table.Rows.Add(dr);
        }
        ds.Tables.Add(table);

        try
        {
            //分页
            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView; //数据绑定
            pgds.AllowPaging = true;    //允许分页
            pgds.PageSize = 60;  //每页数据量
            pgds.CurrentPageIndex = (Convert.ToInt32(ViewState["pagen"]));  //设置显示当前第几页
            SetEnable(pgds);    //是否可点

            this.rpTypeByProductList.DataSource = pgds;
            this.rpTypeByProductList.DataBind();
            this.lblTotalPruduct.Text = dTable.Rows[0]["total"].ToString();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    /// <summary>
    /// 设置是否可点
    /// </summary>
    /// <param name="pgds"></param>
    private void SetEnable(PagedDataSource pgds)
    {
        this.lbtnPre.Enabled = true;
        this.lbtnNext.Enabled = true;
        this.lbtnPre2.Enabled = true;
        this.lbtnNext2.Enabled = true;
        if (pgds.CurrentPageIndex == 0)
        {
            this.lbtnPre.Enabled = false;
            this.lbtnPre2.Enabled = false;
            this.lbtnPre.CssClass = "unprev";
            this.lbtnPre2.CssClass = "unprev";
        }
        else if (pgds.CurrentPageIndex == pgds.PageCount - 1)
        {
            this.lbtnNext.Enabled = false;
            this.lbtnNext2.Enabled = false;
            this.lbtnNext.CssClass = "unnext";
            this.lbtnNext2.CssClass = "unnext";
        }
        if (pgds.PageCount == 0)
        {
            this.lblCount.Text = "对不起，没有您要查询的记录！";
            this.lblCount.Visible = true;
            this.lbtnPre.Enabled = false;
            this.lbtnPre2.Enabled = false;
            this.lbtnNext.Enabled = false;
            this.lbtnNext2.Enabled = false;
            this.lbtnPre.CssClass = "unprev";
            this.lbtnPre2.CssClass = "unprev";
            this.lbtnNext.CssClass = "unnext";
            this.lbtnNext2.CssClass = "unnext";
        }
        else if (pgds.PageCount <= 2)
        {
            if (pgds.PageCount == 1)
            {
                this.lbtnNext.Enabled = false;
                this.lbtnNext2.Enabled = false;
                this.lbtnNext.CssClass = "unnext";
                this.lbtnNext2.CssClass = "unnext";
            }
            this.lblCurrentPage.Text = Convert.ToString(pgds.CurrentPageIndex + 1);
            this.lblTotal.Text = pgds.PageCount.ToString();
        }
        else
        {
            this.lblCurrentPage.Text = Convert.ToString(pgds.CurrentPageIndex + 1);
            this.lblTotal.Text = pgds.PageCount.ToString();
        }
    }    
    protected void lbtnPre_Click(object sender, EventArgs e)
    {
        //上一页
        ViewState["pagen"] = ((int)ViewState["pagen"]) - 1; //改变页码
        MyDs();
    }
    protected void lbtnNext_Click(object sender, EventArgs e)
    {
        //下一页
        ViewState["pagen"] = ((int)(ViewState["pagen"])) + 1;
        MyDs();
    }

    protected void ddlPaixu_SelectedIndexChanged(object sender, EventArgs e)
    {
       PaixuPage(this.ddlPaixu.SelectedValue);
    }

    private void PaixuPage(string paixu)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string typeID = Request.QueryString["typeID"];
        string brand = this.txtBrand.Text;
        string type = this.txtType.Text;
        string material = this.txtMaterial.Text;
        string mat = this.txtMat.Text;
        string expirySeason = this.txtExpirySeason.Text;

        if (brand != "0" && type == "0" && material == "" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand));
        }
        else if (type != "0" && brand == "0" && material == "" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type));
        }
        else if (material != "" && brand == "0" && type == "0" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(material) + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(material) + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(material) + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where material like'%" + Int32.Parse(material) + "%'");
        }
        else if (mat != "" && brand == "0" && type == "0" && material == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(mat) + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(mat) + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where material like'%" + Int32.Parse(mat) + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where material like'%" + Int32.Parse(mat) + "%'");
        }
        else if (brand != "0" && type != "0" && material == "" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type));
        }
        else if (brand != "0" && material != "" && type == "0" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + material + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + material + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + material + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and material like'%" + material + "%'");
        }
        else if (brand != "0" && mat != "" && type == "0" && material == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + mat + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + mat + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and material like'%" + mat + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and material like'%" + mat + "%'");
        }
        else if (type != "0" && material != "" && brand == "0" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
        }
        else if (type != "0" && mat != "" && brand == "0" && material == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
        }
        else if (brand != "0" && type != "0" && material != "" && mat == "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
        }
        else if (brand != "0" && type != "0" && material == "" && mat != "" && expirySeason == "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
        }
        else if (brand != "0" && type != "0" && material != "" && mat != "" && expirySeason != "0")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' expirySeason=" + Int32.Parse(expirySeason));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' expirySeason=" + Int32.Parse(expirySeason) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' expirySeason=" + Int32.Parse(expirySeason) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' expirySeason=" + Int32.Parse(expirySeason));
        }
        else if (expirySeason!="0" && brand == "0" && type == "0" && material == "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason));
        }
        else if (expirySeason!="0" && brand != "0" && type == "0" && material == "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand));
        }
        else if (expirySeason!="0" && brand == "0" && type != "0" && material == "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type));
        }
        else if (expirySeason!="0" && brand == "0" && type == "0" && material != "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + material+"%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + material+"%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + material+"%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + material + "%'");
        }
        else if (expirySeason!="0" && brand == "0" && type == "0" && material == "" && mat != "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + mat + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + mat + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + mat + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and material like'%" + mat + "%'");
        }
        else if (expirySeason!="0" && brand != "0" && type != "0" && material == "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type));
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type));
        }
        else if (expirySeason!="0" && brand == "0" && type != "0" && material != "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
        }
        else if (expirySeason!="0" && brand != "0" && type != "0" && material != "" && mat == "")
        {
            switch (paixu)
            {
                case "0":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
                    break;
                case "1":
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice desc");
                    break;
                default:
                    dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' order by wholeSalePrice asc");
                    break;
            }
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason) + " and brandID=" + Int32.Parse(brand) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
        }
        else
        {
            if (typeID!=null)
            {
                switch (paixu)
                {
                    case "0":
                        dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(typeID));
                        break;
                    case "1":
                        dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(typeID) + " order by wholeSalePrice desc");
                        break;
                    default:
                        dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(typeID) + " order by wholeSalePrice asc");
                        break;
                }
                dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(typeID));
            }
            else
            {
                switch (paixu)
                {
                    case "0":
                        dt = productBLL.GetAllProduct("");
                        break;
                    case "1":
                        dt = productBLL.GetAllProduct(" order by wholeSalePrice desc");
                        break;
                    default:
                        dt = productBLL.GetAllProduct(" order by wholeSalePrice asc");
                        break;
                }
                dTable = productBLL.GetTotal("");
            }   
        }
        proPage(dt,dTable);
    }

    /// <summary>
    /// 品牌筛选
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnBrand_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string type = "";
        if (Request.QueryString["typeID"]!=null)
        {
            type = Request.QueryString["typeID"];
        }
        else if (this.txtType.Text!="0")
        {
            type = this.txtType.Text;
        }
        else
        {
            type = "0";
        }
        string material = this.txtMaterial.Text;
        string mat = this.txtMat.Text;
        string expirySeason = this.txtExpirySeason.Text;
        string brandID = ((LinkButton)sender).CommandArgument;
        this.txtBrand.Text = brandID;
        if (type!="0" && material=="" && mat=="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Int32.Parse(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type=="0" && material!="" && mat=="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString(); 
        }
        else if (type=="0" && material=="" && mat!="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%'");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type!="0" && material!="" && mat=="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Int32.Parse(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type!="0" && material=="" && mat!="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Int32.Parse(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type!="0" && material!="" && mat!="")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Int32.Parse(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID)+" and typeID=" + Int32.Parse(type));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID)+" and typeID=" + Int32.Parse(type));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        proPage(dt, dTable);
        this.panelBrand.Visible = false;
    }

    /// <summary>
    /// 类型筛选
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnType_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string brandID = this.txtBrand.Text;
        string typeID = ((LinkButton)sender).CommandArgument;
        this.txtType.Text = typeID;
        if (brandID != "0")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(typeID));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(typeID));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(typeID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(typeID));
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(typeID));
            proType = proTypeBLL.GetModel(Int32.Parse(typeID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
        }
        proPage(dt, dTable);
        this.panelType.Visible = false;
    }

    protected void lbtnMaterial_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string brandID = this.txtBrand.Text;
        string type = "";
        if (Request.QueryString["typeID"] != null)
        {
            type = Request.QueryString["typeID"];
        }
        else if (this.txtType.Text != "0")
        {
            type = this.txtType.Text;
        }
        else
        {
            type = "0";
        }
        string material = ((LinkButton)sender).CommandArgument;
        this.txtMaterial.Text = material;
        if (brandID != "0")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", brand.brandID,  brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type != "0")
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else
        {
            dt = productBLL.GetAllProduct("where material like'%" + material + "%'");
            dTable = productBLL.GetTotal("where material like'%" + material + "%'");
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        proPage(dt, dTable);
        this.panelMaterial.Visible = false;
    }

    protected void lbtnMat_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string brandID = this.txtBrand.Text;
        string type = "";
        if (Request.QueryString["typeID"] != null)
        {
            type = Request.QueryString["typeID"];
        }
        else if (this.txtType.Text != "0")
        {
            type = this.txtType.Text;
        }
        else
        {
            type = "0";
        }
        //string material = this.txtMaterial.Text;
        string mat = ((LinkButton)sender).CommandArgument;
        this.txtMat.Text = mat;
        if (brandID != "0")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type != "0")
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%'");
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else
        {
            dt = productBLL.GetAllProduct("where material like'%" + mat + "%'");
            dTable = productBLL.GetTotal("where material like'%" + mat + "%'");
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        proPage(dt, dTable);
        this.panelMat.Visible = false;
    }

    protected void lbtnExpirySeason_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataTable dTable = new DataTable();
        string brandID = this.txtBrand.Text;
        string type = "";
        if (Request.QueryString["typeID"] != null)
        {
            type = Request.QueryString["typeID"];
        }
        else if (this.txtType.Text != "0")
        {
            type = this.txtType.Text;
        }
        else
        {
            type = "0";
        }
        string material = this.txtMaterial.Text;
        string mat = this.txtMat.Text;
        string expirySeason = ((LinkButton)sender).CommandArgument;
        string txtExpirySeason = "";
        switch (expirySeason)
        {
            case "1":
                this.txtExpirySeason.Text = "0";
                txtExpirySeason="春季";
                break;
            case "2":
                this.txtExpirySeason.Text = "1";
                txtExpirySeason="夏季";
                break;
            case "3":
                this.txtExpirySeason.Text = "2";
                txtExpirySeason="秋季";
                break;
            default:
                this.txtExpirySeason.Text = "3";
                txtExpirySeason="冬季";
                break;
        }
        if (brandID != "0" && type == "0" && material == "" && mat == "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type != "0" && brandID == "0" && material == "" && mat == "")
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and expirySeason=" + Int32.Parse(expirySeason));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (material != "" && brandID == "0" && type == "0" && mat == "")
        {
            dt = productBLL.GetAllProduct("where material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (mat != "" && brandID == "0" && type == "0" && material == "")
        {
            dt = productBLL.GetAllProduct("where material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0" && material == "" && mat == "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && material != "" && type == "0" && mat == "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + " like'%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + material + " like'%' and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && mat != "" && type == "0" && material == "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type != "0" && material != "" && brandID == "0" && mat == "")
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (type != "0" && mat != "" && brandID == "0" && material == "")
        {
            dt = productBLL.GetAllProduct("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0" && material != "" && mat == "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?material={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0" && material == "" && mat != "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else if (brandID != "0" && type != "0" && material != "" && mat != "")
        {
            dt = productBLL.GetAllProduct("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where brandID=" + Int32.Parse(brandID) + " and typeID=" + Int32.Parse(type) + " and material like'%" + material + "%' and material like'%" + mat + "%' and expirySeason=" + Int32.Parse(expirySeason));
            brand = brandBLL.GetByBrand(Int32.Parse(brandID));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?brandID={0}'>{1}</a>", brand.brandID, brand.brand_name);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", material, material);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?mat={0}'>{1}</a>", mat, mat);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        else
        {
            dt = productBLL.GetAllProduct("where expirySeason=" + Int32.Parse(expirySeason));
            dTable = productBLL.GetTotal("where expirySeason=" + Int32.Parse(expirySeason));
            proType = proTypeBLL.GetModel(Convert.ToInt32(type));
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}'>{1}</a>", proType.typeId, proType.typeName);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            sb.Append("<span>");
            sb.AppendFormat("<a href='gallery-grid.aspx?expirySeason={0}'>{1}</a>", expirySeason, txtExpirySeason);
            sb.Append("</span>");
            sb.Append("<span>&raquo;</span>");
            this.pSitemaps.InnerHtml = sb.ToString();
        }
        proPage(dt, dTable);
        if (brandID!="0" && type!="0" && material!="" && mat!="")
        {
            this.panelTable.Visible = false;
        }
        else
        {
            this.panelExpirySeason.Visible = false;
        }
    }
}
